package com.aoyy.util.order;

import java.util.Map;
import org.apache.struts2.util.StrutsTypeConverter;
/**=====================================================================
 * <code>OrderStateConverter</code> class for order state converter
 * @author Administrator
 * @date 2017-07-12
 * ====================================================================== */
public class StateConverter extends StrutsTypeConverter {
  @SuppressWarnings("rawtypes") 
  @Override
  public Object convertFromString(Map arg0, String[] arg1, Class arg2) {
    State[] states = State.values();
    for (State state: states) {
      if (state.getName().equals(arg1[0])) {
    	return state;  
      }
    }
    return null;
  }

  @Override
  public String convertToString(@SuppressWarnings("rawtypes") Map arg0, Object arg1) {
    return ((State) arg1).getName();	  
  }

}
